package com.mdnote.jianzhi_offer.linked_list;

/**
 * @author Rhythm-2019
 * @version 1.0
 * @date 2020/11/10 0:50
 * @Email rhythm_2019@163.com
 * @Description 剑指 Offer 24. 反转链表
 */
public class Offer24 {
    public ListNode reverseList(ListNode head) {

        ListNode cur = head, pre = null;
        while (cur != null) {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }

        return pre;
    }


    public static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }
}
